package cn.rick.mapper;

import cn.rick.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜单权限表 Mapper 接口
 * </p>
 *
 * @author house_store
 * @since 2022-10-19 14:39:46
 */
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    /**
     * 通过用户id查询菜单列表
     *
     * @param userId
     * @return
     */
    @Select("SELECT m.*\n" +
            "FROM sys_user u\n" +
            "INNER JOIN sys_user_role ur ON u.user_id = ur.user_id\n" +
            "INNER JOIN sys_role r ON ur.role_id = r.role_id\n" +
            "INNER JOIN sys_role_menu rm ON r.role_id = rm.role_id\n" +
            "INNER JOIN sys_menu m ON rm.menu_id = m.menu_id\n" +
            "WHERE u.user_id = #{userId}\n" +
            "GROUP BY m.menu_id\n" +
            "ORDER BY m.order_num")
    List<SysMenu> selectAllByUserId(@Param(value = "userId") Long userId);

}
